CSharpTest.Net
Remove Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Collections Namespace > SynchronizedList<T> Class : Remove Method

item

Glossary Item Box

Removes the first occurrence of a specific object from the ICollection.

Syntax

Visual Basic (Declaration) 
Public Function Remove( _
   ByVal item As T _
) As Boolean
C# 
public bool Remove( 
   T item
)

Parameters

item

Example

Library/Library.Test/TestSynchronizedCollections.cs

C#Copy Code
LockCounterFactory<SimpleReadWriteLocking> factory = new LockCounterFactory<SimpleReadWriteLocking>();
ILockStrategy lck = factory.Create();
SynchronizedList<int> list = new SynchronizedList<int>(lck);

Assert.IsTrue(ReferenceEquals(lck, list.Lock));
list.Add(42);
Assert.AreEqual(1, factory.TotalWriterCount);
Assert.AreEqual(0, factory.TotalReaderCount);

list[0] = 51;
Assert.AreEqual(2, factory.TotalWriterCount);

list.Insert(1, 52);
Assert.AreEqual(3, factory.TotalWriterCount);

list.RemoveAt(1);
Assert.AreEqual(4, factory.TotalWriterCount);

list.Remove(-1);
Assert.AreEqual(5, factory.TotalWriterCount);

Assert.AreEqual(51, list[0]);
Assert.AreEqual(1, factory.TotalReaderCount);

foreach (int i in list)
    GC.KeepAlive(i);
Assert.AreEqual(2, factory.TotalReaderCount);

Assert.AreEqual(0, list.IndexOf(51));
Assert.AreEqual(3, factory.TotalReaderCount);

Assert.AreEqual(1, list.Count);
Assert.AreEqual(4, factory.TotalReaderCount);
VB.NETCopy Code
Dim factory As New LockCounterFactory(Of SimpleReadWriteLocking)()
Dim lck As ILockStrategy = factory.Create()
Dim list As New SynchronizedList(Of Integer)(lck)

Assert.IsTrue(ReferenceEquals(lck, list.Lock))
list.Add(42)
Assert.AreEqual(1, factory.TotalWriterCount)
Assert.AreEqual(0, factory.TotalReaderCount)

list(0) = 51
Assert.AreEqual(2, factory.TotalWriterCount)

list.Insert(1, 52)
Assert.AreEqual(3, factory.TotalWriterCount)

list.RemoveAt(1)
Assert.AreEqual(4, factory.TotalWriterCount)

list.Remove(-1)
Assert.AreEqual(5, factory.TotalWriterCount)

Assert.AreEqual(51, list(0))
Assert.AreEqual(1, factory.TotalReaderCount)

For Each i As Integer In list
    GC.KeepAlive(i)
Next
Assert.AreEqual(2, factory.TotalReaderCount)

Assert.AreEqual(0, list.IndexOf(51))
Assert.AreEqual(3, factory.TotalReaderCount)

Assert.AreEqual(1, list.Count)
Assert.AreEqual(4, factory.TotalReaderCount)

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys